package com.heima.listener;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.heima.pojo.Student;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class TopicListener {

    @KafkaListener(topics = {"TopicSource"})
    public void receiveMessage(ConsumerRecord<String, String> record) {
        log.info("收到了生产者发来的消息,参数为{}", record);
        System.out.println("该消息的键为：" + record.key());
        System.out.println("收到了你的值：" + record.value());
        System.out.println(JSON.parseObject(record.value(), Student.class));
    }
}
